import React, { Component } from 'react';
import { Form, Input, Button, message } from 'antd';
import { getMemberInfo } from '../../../../utils/auth'
import memberApi from '../../../../api/member'
class Security extends Component {

  passwordRef = React.createRef()

  changePassword = (data) => {
    const id = getMemberInfo().id
    let jsonData = { id, ...data }
    memberApi.changePassword(jsonData).then(res => {
      if (res.success) {
        message.success("修改密码成功")
        this.formRef.current.setFieldsValue({
          "oldPassword": "",
          "newPassword": ""
        })
      }
    }).catch(err => {
      console.log(err);
    })
  }
  phoneRef = React.createRef()
  changeEmail = ()=>{}
  render() {
    return (
      <div style={{ padding: '20px' }}>
        <h2 style={{paddingLeft:'10px'}}>账号：{getMemberInfo().phone}</h2>
        <Form
          onFinish={this.changePassword}
          ref={this.passwordRef}
        >
          <Form.Item
            label="原密码"
            name="oldPassword"
            rules={[{ required: true, message: '请输入原密码!' }]}
          >
            <Input.Password />
          </Form.Item>

          <Form.Item
            label="新密码"
            name="newPassword"
            rules={[{ required: true, message: '请输入新密码!' }]}
          >
            <Input.Password />
          </Form.Item>
          <Form.Item style={{ textAlign: 'right' }}>
            <Button type="primary" htmlType="submit">设置密码</Button>
          </Form.Item>
        </Form>
      </div>
    );
  }
}

export default Security;